package com.huawei.crm.query;

import com.huawei.crm.util.DateUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.StringUtils;

import java.util.Date;

@Setter
@Getter
public class CustomerReportQueryObject extends QueryObject {


    private String keyword;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endTime;

    private String groupType = "seller.name";

    public String getGroupTypeName() {
        String name = "";
        if ("seller.name".equals(groupType)) {
            name = "营销人员";
        } else if ("DATE_FORMAT(c.input_time, '%Y')".equals(groupType)) {
            name = "年";
        } else if ("DATE_FORMAT(c.input_time, '%Y-%m')".equals(groupType)) {
            name = "月";
        } else {
            name = "日";
        }
        return name;
    }


    public Date getEndTime() {
        return DateUtil.getEndDate(endTime);
    }


    //如果字符串类型的参数为null或者空字符串,统一返回null
    public String getKeyword() {
        return StringUtils.isEmpty(keyword) ? null : keyword;
    }
}
